<template>
	<view class="home">
		<swiper class="swiper" circular autoplay>
			<swiper-item>
				<view class="bannerbox"></view>
			</swiper-item>
			<swiper-item>
				<view class="bannerbox"></view>
			</swiper-item>
			<swiper-item>
				<view class="bannerbox"></view>
			</swiper-item>
		</swiper>
		<view class="announcement">
			<view class="txt">限时特价：只有998元就可以升级为团长，快来火速加入</view>
		</view>
		<view class="qrcodebox">
			<view class="box" @click="wifiCliekPage('page1')">
				<image src="../../static/svg/wifi.svg" class="icon"></image>
				<div class="titlebox">
					<div class="title">创建WIFI码</div>
					<div class="subTitle">一键连接安全防蹭网</div>
				</div>
			</view>
			<view class="box" @click="wifiCliekPage('page2')">
				<image src="../../static/svg/mywifi.svg" class="icon"></image>
				<div class="titlebox">
					<div class="title">我的WIFI码</div>
					<div class="subTitle">查看管理智能WIFI码</div>
				</div>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		onLoad() {

		},
		methods: {
			wifiCliekPage(viewPage) {
			    // 校验用户是否已授权
			    let userInfo = uni.getStorageSync('userInfo');
			    console.log(userInfo);
			    if (!userInfo) {
			      // 跳转鉴权页面，获取鉴权信息
			      // this.onGetUserInfo(viewPage);
				  uni.navigateTo({
				  	url:'/pages/my/login'
				  })
			    } else {
			      // 如果用户信息已经存在，直接跳转页面
			      let pageUrl = "/pages/home/createQrcode/createQrcode";
			      if (viewPage == 'page2') {
			        // pageUrl = "/pages/wifiClient/wifiConnection";
					pageUrl = "/pages/home/manageQrcode/manageQrcode";
			      }
			      uni.navigateTo({ url: pageUrl });
			    }
			},
			
			async onGetUserInfo(viewPage) {
			    try {
			      // 显示模态对话框询问用户是否愿意授权
			      const modalResult = await uni.showModal({
			        title: '提示',
			        content: '是否授权获取您的信息？',
			        showCancel: true,
			        cancelText: '取消',
			        confirmText: '确定'
			      });
			
			    if (modalResult.confirm) {
			        // 用户点击确定，尝试获取用户信息
			        const profileResult = await uni.getUserProfile({
			          desc: '用于完善会员资料'
			        });
			
			        if (profileResult.errMsg === 'getUserProfile:ok') {
			          // 用户信息获取成功
			          const userInfo = profileResult.userInfo;
			          console.log(userInfo);
			          // 保存用户信息到本地存储
			          uni.setStorageSync('userInfo', userInfo);
			          // 页面跳转
			          let pageUrl = "/pages/home/createQrcode/createQrcode";
			          if (viewPage == 'page2') {
			            pageUrl = "/pages/wifiClient/wifiConnection";
			          }
			          uni.navigateTo({ url: pageUrl });
			        }
			      } else {
			        // 用户点击取消
			        console.log('用户拒绝授权');
			      }
			    } catch (error) {
			      // 处理错误情况
			      console.error('获取用户信息失败:', error);
			    }
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '../../static/style/mixin.scss';

	.home {
		width: 100vw;

		.swiper {
			height: 450upx;

			.bannerbox {
				width: 100vw;
				height: 450upx;
				background-image: linear-gradient(90deg, aqua, #f89);
			}
		}

		.announcement {
			width: inherit;
			height: 60upx;
			line-height: 60upx;
			font-size: 25upx;
			position: relative;
			overflow: hidden;
			animation: move 10s infinite linear;
		}

		@keyframes move {
			from {
				right: -750upx;
			}

			to {
				right: 750upx;
			}

		}

		.qrcodebox {
			padding-left: 20upx;
			display: flex;

			.box {
				box-sizing: border-box;
				padding: 15upx;
				width: 345upx;
				height: 130upx;
				margin-right: 20upx;
				border-radius: 10upx;
				background-image: linear-gradient(90deg, aqua, #f89);
				display: flex;
				align-items: center;

				.icon {
					width: 80upx;
					height: 80upx;
					margin-right: 15upx;
				}

				.titlebox {
					width: 220upx;

					.title {
						font-size: 35upx;
					}

					.subTitle {
						font-size: 20upx;
					}
				}
			}
		}
	}
</style>
